package com.longcai.controller.fuyoupay;





import java.time.LocalDateTime;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.longcai.bean.ApiResult;
import com.longcai.entity.payment.fuyou.request.ClyjFuyouSubamountProportion;
import com.longcai.enums.ResultEnum;
import com.longcai.service.fuyoupay.ClyjFuyouSubamountProportionService;
import com.longcai.util.StringUtils;
import com.longcai.util.UUIDUtil;

/**
 * 富友支付分账规则中--分账比例的设定 
 * @author hyf
 */
@Controller
@RequestMapping("/clyjFuyouSubamountProportion")
public class ClyjFuyouSubamountProportionController {

	
	@Resource
	private ClyjFuyouSubamountProportionService clyjFuyouSubamountProportionService;
	
	
	/**
	 * 根据角色，和销售渠道设置分账比例
	 * @return
	 */
	@RequestMapping(value="/setSubamountProportion")
	@ResponseBody
	public ApiResult<?> setSubamountProportion(@RequestBody JSONObject params){
		ClyjFuyouSubamountProportion cysp=new ClyjFuyouSubamountProportion();
		if(StringUtils.isEmpty(params.getString("ruleId"))||StringUtils.isEmpty(params.getString("salesChannel"))||StringUtils.isEmpty(params.getString("proportion"))){
			return ApiResult.fail(ResultEnum.BAD_REQUEST_PARAMETER);
		}
		cysp.setId(UUIDUtil.uuid());
		cysp.setRuleId(params.getString("ruleId"));
		cysp.setSalesChannel(params.getString("salesChannel"));
		cysp.setProportion(params.getString("proportion"));
		cysp.setCreater("");
		cysp.setCreateTime(LocalDateTime.now());
		boolean b=clyjFuyouSubamountProportionService.insert(cysp);
		if(b){
			return ApiResult.success();
		}
		return ApiResult.fail(ResultEnum.SET_SUBAMOUNT_PROPORTION_FAIL);
	}
	/**
	 * 修改分账比例
	 * @return
	 */
	@RequestMapping(value="/modifySubamountProportion")
	@ResponseBody
	public ApiResult<?> modifySubamountProportion(@RequestBody JSONObject params){
		ClyjFuyouSubamountProportion cysp=new ClyjFuyouSubamountProportion();
		if(StringUtils.isEmpty(params.getString("id"))||StringUtils.isEmpty(params.getString("ruleId"))||StringUtils.isEmpty(params.getString("salesChannel"))||StringUtils.isEmpty(params.getString("proportion"))){
			return ApiResult.fail(ResultEnum.BAD_REQUEST_PARAMETER);
		}
		cysp.setId(params.getString("id"));
		cysp.setRuleId(params.getString("ruleId"));
		cysp.setSalesChannel(params.getString("salesChannel"));
		cysp.setProportion(params.getString("proportion"));
		cysp.setReviser("");
		cysp.setReviserTime(LocalDateTime.now());
		boolean b=clyjFuyouSubamountProportionService.updateById(cysp);
		if(b){
			return ApiResult.success();
		}
		return ApiResult.fail(ResultEnum.SET_SUBAMOUNT_PROPORTION_FAIL);
	}
	/**
	 * 修改分账比例状态
	 * @return
	 */
	@RequestMapping(value="/modifySubamountProportionStatus")
	@ResponseBody
	public ApiResult<?> modifySubamountProportionStatus(@RequestBody JSONObject params){
		ClyjFuyouSubamountProportion cysp=new ClyjFuyouSubamountProportion();
		if(StringUtils.isEmpty(params.getString("id"))||StringUtils.isEmpty(params.getString("status"))){
			return ApiResult.fail(ResultEnum.BAD_REQUEST_PARAMETER);
		}
		cysp.setId(params.getString("id"));
		cysp.setRuleId(params.getString("status"));/** 状态0，启用1，停用 */
		cysp.setReviser("");
		cysp.setReviserTime(LocalDateTime.now());
		boolean b=clyjFuyouSubamountProportionService.updateById(cysp);
		if(b){
			return ApiResult.success();
		}
		return ApiResult.fail(ResultEnum.MODIFY_SUBAMOUNT_PROPORTION_STATUS_FAIL);
	}
	
}

